package com.ruoyi.web.controller.campus;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.UUID;

import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.campus.domain.MyComment;
import com.ruoyi.campus.service.IMyCommentService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 留言板评论Controller
 *
 * @author zht
 * @date 2021-10-24
 */
@RestController
@RequestMapping("/campus/comment")
public class MyCommentController extends BaseController
{
    @Autowired
    private IMyCommentService myCommentService;

    /**
     * 查询留言板评论列表
     */
    @PreAuthorize("@ss.hasPermi('campus:comment:list')")
    @GetMapping("/list")
    public TableDataInfo list(MyComment myComment)
    {
        startPage();
        List<MyComment> list = myCommentService.selectMyCommentList(myComment);
        return getDataTable(list);
    }

    /**
     * 导出留言板评论列表
     */
    @PreAuthorize("@ss.hasPermi('campus:comment:export')")
    @Log(title = "留言板评论", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(MyComment myComment)
    {
        List<MyComment> list = myCommentService.selectMyCommentList(myComment);
        ExcelUtil<MyComment> util = new ExcelUtil<MyComment>(MyComment.class);
        return util.exportExcel(list, "留言板评论数据");
    }

    /**
     * 获取留言板评论详细信息
     */
    @PreAuthorize("@ss.hasPermi('campus:comment:query')")
    @GetMapping(value = "/{cId}")
    public AjaxResult getInfo(@PathVariable("cId") String cId)
    {
        return AjaxResult.success(myCommentService.selectMyCommentByCId(cId));
    }

    /**
     * 新增留言板评论
     */
    @PreAuthorize("@ss.hasPermi('campus:comment:add')")
    @Log(title = "留言板评论", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody MyComment myComment)
    {
        myComment.setcId(UUID.randomUUID().toString().replace("-",""));
        return toAjax(myCommentService.insertMyComment(myComment));
    }

    /**
     * 新增留言板评论(小程序端接口)
     */
    @PreAuthorize("@ss.hasAnyRoles('Administrator,member')")
    @Log(title = "留言板评论", businessType = BusinessType.INSERT)
    @PostMapping("/addForWx")
    public AjaxResult addForWx(@RequestBody MyComment myComment)
    {
        myComment.setCommStatus("3");
        myComment.setcId(UUID.randomUUID().toString().replace("-",""));
        return toAjax(myCommentService.insertMyComment(myComment));
    }

    /**
     * 根据comId查询评论列表(小程序端接口)
     */
    @PreAuthorize("@ss.hasAnyRoles('Administrator,member')")
    @GetMapping("/selectCommentList")
    public AjaxResult selectCommentList(@RequestParam("comId") String comId){
        List<MyComment> commentList = myCommentService.selectCommentList(comId);
        if (commentList.size()>0){
            return AjaxResult.success(commentList);
        }else {
            return AjaxResult.error();
        }
    }

    /**
     * 根据cId获取留言板详细信息(小程序端接口)
     */
    @PreAuthorize("@ss.hasAnyRoles('Administrator,member')")
    @GetMapping("/getCommentByCId")
    public Map<String,Object> getCommentByCId(@RequestParam("cId") String cId){
        return  myCommentService.getCommentByCId(cId);
    }

    /**
     * 获取个人未读信息(小程序接口)
     */
    @PreAuthorize("@ss.hasAnyRoles('Administrator,member')")
    @GetMapping("/getMessageByUserId")
    public List<Map<String,Object>> getMessageByUserId(@RequestParam("userId") String userId){
        return  myCommentService.getMessageByUserId(userId);
    }



    /**
     * 修改留言板评论
     */
    @PreAuthorize("@ss.hasPermi('campus:comment:edit')")
    @Log(title = "留言板评论", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody MyComment myComment)
    {
        return toAjax(myCommentService.updateMyComment(myComment));
    }

    /**
     * 删除留言板评论
     */
    @PreAuthorize("@ss.hasPermi('campus:comment:remove')")
    @Log(title = "留言板评论", businessType = BusinessType.DELETE)
	@DeleteMapping("/{cIds}")
    public AjaxResult remove(@PathVariable String[] cIds)
    {
        return toAjax(myCommentService.deleteMyCommentByCIds(cIds));
    }
}
